﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using VNet.VisiSuite.Service.Proxy;
using VNet.VisiSuite.Service.Contact.Message.Base;
using VNet.VisiSuite.Common.Security;
using VNet.VisiSuite.Service.Contact.Message.Item;

namespace VNet.VisiSuite.VisiAdmin.Providers
{
    public class AreaProvider
    {
        #region Area
        public static void InsertArea(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AreaItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AreaItem,
                    };
                    e.Result = client.InsertArea(request);
                }
            }
        }

        public static void UpdateArea(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AreaItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AreaItem,
                    };
                    e.Result = client.UpdateArea(request);
                }
            }
        }

        public static void DeleteArea(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteArea(request);
                }
            }
        }
        #endregion
        
        #region AreaShift
        public static void GetAreaShifts(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetAreaShifts(request);
                }
            }
        }

        public static void InsertAreaShift(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AreaShiftItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AreaShiftItem,
                    };
                    e.Result = client.InsertAreaShift(request);
                }
            }
        }

        public static void UpdateAreaShift(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AreaShiftItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AreaShiftItem,
                    };
                    e.Result = client.UpdateAreaShift(request);
                }
            }
        }

        public static void DeleteAreaShift(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteAreaShift(request);
                }
            }
        }
        #endregion

        #region LaunchApplication

        public static void GetLaunchApplications(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetLaunchApplications(request);
                }
            }
        }

        public static void InsertLaunchApplication(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<LaunchApplicationItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as LaunchApplicationItem,
                    };
                    e.Result = client.InsertLaunchApplication(request);
                }
            }
        }

        public static void UpdateLaunchApplication(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<LaunchApplicationItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as LaunchApplicationItem,
                    };
                    e.Result = client.UpdateLaunchApplication(request);
                }
            }
        }

        public static void DeleteLaunchApplication(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteLaunchApplication(request);
                }
            }
        }

        public static void MoveLaunchApplication(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<LaunchApplicationItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as LaunchApplicationItem,
                    };
                    e.Result = client.MoveLaunchApplication(request);
                }
            }
        }

        #endregion

        #region Reason Code

        public static void GetReasonCodes(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetReasonCodes(request);
                }
            }
        }

        public static void GetRollupDefinitionsAsSource(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetRollupDefinitionsAsSource(request);
                }
            }
        }

        public static void InsertReasonCode(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ReasonCodeItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ReasonCodeItem,
                    };
                    e.Result = client.InsertReasonCode(request);
                }
            }
        }

        public static void UpdateReasonCode(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ReasonCodeItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ReasonCodeItem,
                    };
                    e.Result = client.UpdateReasonCode(request);
                }
            }
        }

        public static void DeleteReasonCode(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteReasonCode(request);
                }
            }
        }

        #endregion

        #region RollupDefinition
        public static void GetRollupDefinitions(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetRollupDefinitions(request);
                }
            }
        }

        public static void DeleteRollupDef(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteRollupDefinition(request);
                }
            }
        }

        public static void InsertRollupDef(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<RollupDefinitionItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as RollupDefinitionItem,
                    };
                    e.Result = client.InsertRollupDefinition(request);
                }
            }
        }

        public static void UpdateRollupDef(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<RollupDefinitionItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as RollupDefinitionItem,
                    };
                    e.Result = client.UpdateRollupDefinition(request);
                }
            }
        }

        public static void MoveRollupDefinition(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<RollupDefinitionItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as RollupDefinitionItem,
                    };
                    e.Result = client.MoveRollupDefinition(request);
                }
            }
        }

        #endregion

        #region ScrapReasonCode
        public static void GetScrapReasonCodes(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetScrapReasonCodes(request);
                }
            }
        }

        #endregion

        #region Alarm Setting
        public static void GetAlarmSettings(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument,
                    };
                    e.Result = client.GetAlarmSettings(request);
                }
            }
        }

        public static void DeleteAlarmSetting(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteAlarmSetting(request);
                }
            }
        }

        public static void InsertAlarmSetting(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AlarmSettingItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AlarmSettingItem,
                    };
                    e.Result = client.InsertAlarmSetting(request);
                }
            }
        }

        public static void UpdateAlarmSetting(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<AlarmSettingItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as AlarmSettingItem,
                    };
                    e.Result = client.UpdateAlarmSetting(request);
                }
            }
        }

        #endregion

        #region Scheduled Downtime

        public static void GetScheduledDowntimes(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;

            if (worker == null || worker.CancellationPending || worker.CancellationPending)
            {
                return;
            }

            var client = new VNetVisiSuiteContractClient();
            var request = new GetDataRequest
            {
                Identity = UserTransportToken.UserIdentity,
                Id = (int) e.Argument,
            };
            e.Result = client.GetScheduledDowntimes(request);
        }

        public static void DeleteScheduleDowntime(object sendder, DoWorkEventArgs e)
        {
            var worker = sendder as BackgroundWorker;
            e.Result = null;
            if(worker !=null && worker.CancellationPending == false)
            {
                if(worker!=null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                                      {
                                          Identity = UserTransportToken.UserIdentity,
                                          DataId = (int) e.Argument
                                      };
                    e.Result = client.DeleteScheduledDowntime(request);
                }
            }
        }


        public static void InsertScheduleDowntime (object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ScheduledDowntimeItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ScheduledDowntimeItem,
                    };
                    e.Result = client.InsertScheduledDowntime(request);
                }
            }
        }

        public static void UpdateScheduledDowntime(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ScheduledDowntimeItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ScheduledDowntimeItem,
                    };
                    e.Result = client.UpdateScheduledDowntime(request);
                }
            }
        }



        #endregion

        #region Scheduled Repeat

        public static void GetScheduledRepeat(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;

            if (worker == null || worker.CancellationPending || worker.CancellationPending)
            {
                return;
            }

            var client = new VNetVisiSuiteContractClient();
            var request = new GetDataRequest
            {
                Identity = UserTransportToken.UserIdentity,
                Id = (int)e.Argument,
            };
            e.Result = client.GetScheduledRepeat(request);
        }

        public static void DeleteScheduledRepeat(object sendder, DoWorkEventArgs e)
        {
            var worker = sendder as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument
                    };
                    e.Result = client.DeleteScheduledRepeat(request);
                }
            }
        }


        public static void InsertScheduleRepeat(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ScheduledRepeatItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ScheduledRepeatItem,
                    };
                    e.Result = client.InsertScheduleRepeat(request);
                }
            }
        }

        public static void UpdateScheduleRepeat(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<ScheduledRepeatItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as ScheduledRepeatItem,
                    };
                    e.Result = client.UpdateScheduleRepeat(request);
                }
            }
        }



        #endregion

    }
}
